package com.yijumao.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yijumao.dao.UserFileDao;
import com.yijumao.entity.UserFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

/**
 * @author konley
 * @date 2020-10-26 22:15
 */
@Service
public class UserFileServiceImpl implements UserFileService{
    @Autowired
    private UserFileDao userFileDao;


    @Override
    public List<UserFile> findByUserId(Integer id) {
        QueryWrapper<UserFile> queryWrapper = new QueryWrapper<UserFile>()
                .eq("user_id",id);
        return userFileDao.selectList(queryWrapper);
    }

    @Override
    public void save(UserFile userFile) {
        //判断是否为图片：判断类型中是否image字符串开头
        if(userFile.getType().startsWith("image")){
            userFile.setIsImg("是");
        }else {
            userFile.setIsImg("否");
        }

        userFile.setDowncounts(0);
        userFile.setUploadTime(new Date(System.currentTimeMillis()));
        userFileDao.insert(userFile);
    }
}
